package br.com.rafael.gestorinvestimentos.DAO;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.rafael.gestorinvestimentos.model.Acao;

public class AcaoDAO{
	private Session session;
	
	public AcaoDAO(Session session){
		this.session = session;
	}	
	
	public void insert (Acao acao){
		this.session.save(acao);
	}
	
	public void update (Acao acao){
		this.session.merge(acao);
	}
	
	public void delete (Acao acao){
		this.session.delete(acao);
	}
	
	public Acao getAcao (int id){
		return (Acao) session.load(Acao.class, id);
	
	}
	
	public Acao getAcao (String ticker){
		Query q = this.session.createQuery("from Acao as acao where acao.ticker = :acaoTicker").setParameter("acaoTicker", ticker);
		return (Acao) q.uniqueResult();
	}
	
	public Acao getAcaoNome (String nome){
		Query q = this.session.createQuery("from Acao as acao where acao.nome = :acaoNome").setParameter("acaoNome", nome);
		return (Acao) q.uniqueResult();
	}
		
	public List getList (){
		return this.session.createCriteria(Acao.class).list();
	}


}
